/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: TryCatch
 * Author:   AEO WUGUOZHI
 * Date:     2020/7/14 16:31
 * Description: none
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.imooc.Test;

/**
 * 〈一句话功能简述〉<br> 
 * 〈none〉
 *
 * @author AEO WUGUOZHI
 * @create 2020/7/14
 * @since 1.0.0
 */
public class TryCatch {

    public static void main(String[] args) {
        TryCatch tct = new TryCatch();
        int result = tct.test();
        System.out.println(result);

        result = tct.test2();
        System.out.println(result);
    }

/*
* divider等于0，所以异常被catch语句捕获，
* */
    public int test(){
        int divider = 10;
        int result = 100;
        try {
            while(divider > -1){
                divider--;
                result = result + 100/divider;
            }
            return result;
        }catch (Exception ex){
            ex.printStackTrace();
            System.out.println("抛出异常");
            return -1;
        }
    }

/*
*try语句块里面有异常，然后按顺序匹配catch（）里面的异常类，然后执行finally语句。
* */
    public int test2(){
        int divider = 10;
        int result = 100;
        try {
            while(divider > -1){
                divider--;
                result = result + 100/divider;
            }
            return result;
        }catch (Exception ex){
            ex.printStackTrace();
            System.out.println("抛出异常test2");
            return result = 999;
        }finally{
            System.out.println("我是finally语句块");
            System.out.println("result:" + result);
        }
    }

}
